/**
 * Created by Administrator on 2016/3/24 0024.
 */
function checkdate(date) {
    if (date > 9) {
        return date;
    } else {
        return '0' + date;
    }
}

function getlastmonth() {
    var now = new Date();
    var month = now.getMonth() + 1;
    if (month == 1) {
        now.setMonth(12);
    } else {
        now.setMonth(month - 1);
    }
    var day = new Date(now.getFullYear(), now.getMonth(), 0);
    var endDate = now.getFullYear() + '-' + checkdate(now.getMonth()) + '-' + day.getDate();
    var startDate = now.getFullYear() + '-' + checkdate(now.getMonth()) + '-01';
    $("#startDate").val(startDate);
    $("#endDate").val(endDate);
}

function getlastweek() {
    var now = new Date();
    var date = now.getDate();
    var week = now.getDay();
    if (week == 0) {
        week = 7;
    }
    now.setDate(date - week);
    var realEndMonth = now.getMonth() + 1;
    var endDate = now.getFullYear() + '-' + checkdate(realEndMonth) + '-' + checkdate(now.getDate());
    now.setDate(now.getDate() - 6);
    var realStartMonth = now.getMonth() + 1;
    var startDate = now.getFullYear() + '-' + checkdate(realStartMonth) + '-' + checkdate(now.getDate());
    $("#startDate").val(startDate);
    $("#endDate").val(endDate);
}

function getlastday(){
    var now = new Date();
    var date = now.getDate();
    now.setDate(date-1);
    var realEndMonth = now.getMonth() + 1;
    var startDate = now.getFullYear() + '-' + checkdate(realEndMonth) + '-' + checkdate(now.getDate());
    $("#startDate").val(startDate);
    $("#endDate").val(startDate);
}


$(function() {
    //默认时间
    var today = new Date();
    var yestoday = today.getDate() - 1;
    today.setDate(yestoday);
    var thismonth = today.getMonth() + 1;
    $("#endDate").val(today.getFullYear() + '-' + checkdate(thismonth) + '-' + checkdate(today.getDate()));
    var sevenago = today.getDate() - 6;
    today.setDate(sevenago);
    var sevenagomonth = today.getMonth() + 1;
    $("#startDate").val(today.getFullYear() + '-' + checkdate(sevenagomonth) + '-' + checkdate(today.getDate()));
});